package cn.com.pc.content.domain.content;

import cn.com.pc.content.domain.Biz;
import cn.com.pc.content.domain.Site;
import cn.com.pc.content.jpa.BizConverter;
import cn.com.pc.content.jpa.SiteConverter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.time.LocalDateTime;

@Data
@ToString
@Entity
@Table(name = "content_drafts")
@AllArgsConstructor
@NoArgsConstructor
public class ContentDraft {
    @Id
    @Column(name = "object_id")
    private String objectId;

    @Column(name = "site")
    @Convert(converter = SiteConverter.class)
    private Site site;

    @Column(name = "biz")
    @Convert(converter = BizConverter.class)
    private Biz biz;

    @JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name = "created_at")
    private LocalDateTime createdAt;
}
